import request from './request.js'
//封装请求的api
const callApi = (url,method,data) => {
    // return request({
    //     url: url,
    //     method: method,
    //     params: method === "GET" ? data : {},
    //     data: method === "POST" ? data : {},
    // });
    const config = { url: url, method: method };
    if(method === 'GET' || method === "DELETE") {
        config.params = data;
    } else if(method === 'POST' || method === "PUT") {
        config.data = data;
    }
    return request(config);
};
export const getApi = (url,data) => callApi(url,'GET',data)
export const postApi = (url,data) => callApi(url,'POST',data)
export const deleteApi = (url,data) => callApi(url,'DELETE',data)
export const putApi = (url,data) => callApi(url,'PUT',data)

// 管理员界面
export const adminApi = {
    // 首页
    getTopTen: data => getApi('/order/getTopTen',data),
    getSumAndPrice: data => getApi('/order/getOrderSum',data),
    // 汉服种类管理
    getAllType: data => getApi('/hanfuType/getTypes',data),
    getAllTypes: data => getApi('/hanfuType/getAllTypes',data),
    getTypeByName: data => getApi('/hanfuType/getTypeByName',data),
    getTypeById: data => getApi('/hanfuType/getTypeById',data),
    addType: data => postApi('/hanfuType/insertType',data),
    changeTypeById: data => putApi('/hanfuType/updateTypes',data),
    deleteType: data => deleteApi('/hanfuType/deleteTypes',data),
    // 汉服店铺管理
    getAllShop: data => getApi('/hanfuShop/getShops',data),
    getAllShops: data => getApi('/hanfuShop/getAllShops',data),
    getShopById: data => getApi('/hanfuShop/getShopById',data),
    getShopByName: data => getApi('/hanfuShop/getShopByName',data),
    addShop: data => postApi('/hanfuShop/insertShop',data),
    changeShopById: data => putApi('/hanfuShop/updateShop',data),
    deleteShop: data => deleteApi('/hanfuShop/deleteShop',data),
    // 汉服管理
    getAllHanfu: data => getApi('/hanfu/getHanfu',data),
    getHanfuById: data => getApi('/hanfu/getHanfuById',data),
    getHanfuByName: data => getApi('/hanfu/getHanfuByName',data),
    getHanfuByStatu: data => getApi('/hanfu/getHanfuByStatu',data),
    addHanfu: data => postApi('/hanfu/insertHanfu',data),
    changeHanfuById: data => putApi('/hanfu/updateHanfu',data),
    deleteHanfu: data => deleteApi('/hanfu/deleteHanfu',data),
    // 用户管理
    getAllCustomer: data => getApi('/customer/getCustomers',data),
    getCustomerById: data => getApi('/customer/getCustomerById',data),
    getCustomerByUsername: data => getApi('/customer/getCustomerByUsername',data),
    getCustomerByPhone: data => getApi('/customer/getCustomerByPhone',data),
    deleteCustomer: data => deleteApi('/customer/deleteCustomer',data),
    // 订单管理
    getAllOrder: data => getApi('/order/getAllOrderNoPage',data)
}

// 用户界面
export const userApi = {
    // 汉服种类科普界面
    getAllType: data => getApi('/hanfuType/getAllTypes',data),
    // 汉服店铺推荐界面
    getAllShop: data => getApi('/hanfuShop/getAllShops',data),
    // 登陆注册界面
    register: data => postApi('/customer/insertCustomer',data),
    login: data => getApi('/customer/toLogin',data),
    fogetPassword: data => putApi('/customer/updateCustomer',data),
    // 首页
    getNewHanfu: data => getApi('/hanfu/getNewHanfu',data),
    getHotHanfu: data => getApi('/hanfu/getHotHanfu',data),
    // 汉服搜索界面
    getAllHanfu: data => getApi('/hanfu/getAllHanfus',data),
    searchByHanfu: data => getApi('/hanfu/getAllHanfusByName',data),
    searchByShop: data => getApi('/hanfu/getAllHanfusByShopName',data),
    searchByType: data => getApi('/hanfu/getAllHanfusByTypeName',data),
    // 购物车界面
    getCartInfo: data => getApi('/cart/getCartInfo',data),
    changeCartInfo: data => putApi('/cart/changeCartInfo',data),
    deleteCartInfo: data => deleteApi('/cart/deleteCartInfo',data),
    // 汉服详情页
    addOrder: data => postApi('/order/insertOrder',data),
    addCartInfo: data => postApi('/cart/addCartInfo',data),
    // 个人信息
    changeSelf: data => putApi('/customer/updateCustomer',data),
    // 历史订单
    getOrders: data => getApi('/order/getOneOrder',data)
}
